import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JPanel;


@SuppressWarnings("serial")
public class myPanel extends JPanel {
	
	int x, y;

	public myPanel() {
        
        addMouseMotionListener(new MouseAdapter() {
            public void mouseDragged(MouseEvent e) {
                x = e.getX();
                y = e.getY();
                repaint(x-10, y-10, 20, 20);
            }
        });
    }

    public Dimension getPreferredSize() {
        return new Dimension(640, 480);
    }

    public void paint(Graphics g) {
        super.paint(g);
        g.setColor(new Color(x%255, y%255, 128));
        g.fillRect(x-10, y-10, 20, 20);
    }
}
